//
//  HNSH_GoodsSpecHeader.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/25.
//

#import "HNSH_GoodsSpecHeader.h"

@interface HNSH_GoodsSpecHeader ()
/** 图 */
@property (nonatomic, strong)UIImageView * imgView;
/** 送积分*/
@property (nonatomic, strong)UILabel * sendJfLabel;
/** 送积分2*/
@property (nonatomic, strong)UILabel * sendJfLabel2;
/** 送积分背景 */
//@property (nonatomic, strong)UIImageView * sendJfBgImgV;
/** 价格 */
@property (nonatomic, strong)UILabel * priceLabel;
/** 数量 */
@property (nonatomic, strong)UILabel * countLabel;
@end

@implementation HNSH_GoodsSpecHeader

//MARK: Cycle Methods
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addAllViews];
        [self addAllLayout];
    }
    return self;
}

- (void)addAllViews{
    [self addSubview:self.imgView];
//    [self addSubview:self.sendJfBgImgV];
//    [self addSubview:self.sendJfLabel];
//    [self addSubview:self.sendJfLabel2];
    [self addSubview:self.priceLabel];
    [self addSubview:self.countLabel];
}

- (void)addAllLayout{
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.width.height.mas_equalTo(90);
        make.top.mas_equalTo(20);
    }];
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.imgView.mas_right).offset(12);
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(self.imgView.mas_top);
    }];
//    [self.sendJfLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(self.imgView.mas_right).offset(15);
//        make.top.mas_equalTo(self.priceLabel.mas_bottom).offset(4);
//        make.height.mas_equalTo(17);
//    }];
//    [self.sendJfLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(self.imgView.mas_right).offset(15);
//        make.top.mas_equalTo(self.sendJfLabel.mas_bottom).offset(2);
//        make.height.mas_equalTo(17);
//    }];
//    [self.sendJfBgImgV mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(self.sendJfLabel.mas_centerY);
//        make.left.mas_equalTo(self.sendJfLabel.mas_left).offset(-6);
//        make.right.mas_equalTo(self.sendJfLabel.mas_right).offset(6);
//        make.height.mas_equalTo(24);
//    }];
    [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.priceLabel);
        make.top.mas_equalTo(self.priceLabel.mas_bottom).offset(4);
        make.height.mas_equalTo(17);
    }];
}

//MARK: Setter Methods
- (void)setSpecModel:(HNSH_GoodsSpecModel *)specModel{
    _specModel = specModel;
    
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:specModel.cover_url] placeholderImage:[UIImage imageNamed:@"icon_place_zfx"]];
    HNSH_GoodsSpecListItem * model = [specModel getCurrentItemModel];
    if (model) {
        self.priceLabel.text = [NSString stringWithFormat:@"¥%@", model.price];
        self.priceLabel.attributedText = [ST_AttributeLabelTool handleLabelWithContent:self.priceLabel.text SelectContent:@"¥" CommonFont:self.priceLabel.font SpeFont:[UIFont systemFontOfSize:17] Color:self.priceLabel.textColor];
        
//        self.sendJfLabel.hidden = [model.reward_amount doubleValue] <= 0;
//        self.sendJfLabel.text = [NSString stringWithFormat:@"赠送购物值：%@", model.reward_amount];
//        
//        self.sendJfLabel2.hidden = [model.reward_integral doubleValue] <= 0;
//        self.sendJfLabel2.text = [NSString stringWithFormat:@"赠送冻结能量：%@", model.reward_integral];
        
        self.countLabel.text = [NSString stringWithFormat:@"库存：%@", model.store_count];
    } else {
        self.priceLabel.text = @"暂无";
//        self.sendJfLabel.text = @"暂无";
//        self.sendJfLabel2.text = @"";
        self.countLabel.text = @"暂无";
    }
}

- (void)setGoodsDetail:(HNSH_GoodsDetailModel *)goodsDetail {
    _goodsDetail = goodsDetail;
    self.countLabel.hidden = ([goodsDetail.seckill_info.start_time isNotBlank] && [goodsDetail.seckill_info.uid integerValue] > 0);
}

//MARK: Getter Methods
- (UIImageView *)imgView{
    if (!_imgView) {
        _imgView = [UIImageView new];
        _imgView.layer.cornerRadius = 8;
        _imgView.layer.masksToBounds = YES;
    }
    return _imgView;
}

- (UILabel *)sendJfLabel{
    if (!_sendJfLabel) {
        _sendJfLabel = [UILabel new];
        _sendJfLabel.text = @"";
        _sendJfLabel.textColor = [UIColor appOrangeLabelColor];
        _sendJfLabel.font = [UIFont systemFontOfSize:12];
    }
    return _sendJfLabel;
}

- (UILabel *)sendJfLabel2 {
    if (!_sendJfLabel2) {
        _sendJfLabel2 = [UILabel new];
        _sendJfLabel2.text = @"";
        _sendJfLabel2.textColor = [UIColor appOrangeLabelColor];
        _sendJfLabel2.font = [UIFont systemFontOfSize:12];
        _sendJfLabel2.hidden = YES;
    }
    return _sendJfLabel2;
}

//- (UIImageView *)sendJfBgImgV {
//    if (!_sendJfBgImgV) {
//        _sendJfBgImgV = [UIImageView new];
//        _sendJfBgImgV.image = [UIImage imageNamed:@"home_goods_cell_jf_bg"];
//    }
//    return _sendJfBgImgV;
//}

- (UILabel *)priceLabel {
    if (!_priceLabel) {
        _priceLabel = [UILabel new];
        _priceLabel.text = @"";
        _priceLabel.textColor = [UIColor appOrangeLabelColor];
        _priceLabel.font = [UIFont boldSystemFontOfSize:20];
    }
    return _priceLabel;
}
- (UILabel *)countLabel{
    if (!_countLabel) {
        _countLabel = [UILabel new];
        _countLabel.textColor = [UIColor appGrayLabelColor];
        _countLabel.font = [UIFont systemFontOfSize:12];
    }
    return _countLabel;
}

@end
